<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script src="__CDN__/assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
<div class="panel panel-default panel-intro">
    {:build_heading()}

    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <div id="toolbar" class="toolbar">
                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('user/statistic/add')?'':'hide'}" title="{:__('Add')}" > {:__('Add')}</a>
                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('user/statistic/edit')?'':'hide'}" title="{:__('Edit')}" > {:__('Edit')}</a>
                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('user/statistic/del')?'':'hide'}" title="{:__('Delete')}" > {:__('Delete')}</a>
                        <a href="javascript:;" class="btn btn-success bind_shop" title="导入数据" >导入</a>
                        <!--
                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('user/statistic/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false">{:__('Import')}</a>
                        -->
                        (<a href='/assets/js/history.xlsx' download>导入文件示例</a>)

                        

                        
                    </div>
                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                           data-operate-edit="{:$auth->check('user/statistic/edit')}"
                           data-operate-del="{:$auth->check('user/statistic/del')}"
                           width="100%">
                    </table>
                </div>
            </div>

        </div>

        <div class="modal fade" id="showRefundModal" tabindex="-1" role="dialog" aria-labelledby="showRefundModal">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <form id="uploadForm" enctype="multipart/form-data">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="addGoodsLabel">导入用户绑定门店</h4>
                    </div>

                    <div class="modal-body">
                        <div class="">
                            <!-- 外层表格：5行2列 -->
                            <table class="table table-bordered">
                                <tbody>
                                <!-- 第1行 -->
                                <tr>
                                    <td class="col-3">选择绑定门店</td>
                                    <td class="col-9">
                                        <select name="shop_id" class="form-control" style="width:50%;">
                                            {volist name="list" id="item"  key="index" }
                                            <option value="{$item.id}">
                                                {$item.shopname}
                                            </option>
                                            {/volist}
                                        </select>
                                    </td>
                                </tr>
                                <!-- 第2行 -->
                                <tr>
                                    <td>选择需要上传的文件</td>
                                    <td>
                                        <input type="file" id="fileUpload" name="fileUpload" accept=".xls,.xlsx" required/>
                                    </td>
                                </tr>


                                </tbody>
                            </table>

                        </div>
                    </div>

                    <div class="modal-footer model-confirm">
                        <button type="button" class="btn btn-danger btn-confirm-refund-info" id="order_id" onclick="uploadFile()">确认上传</button>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        //选择商品规格
        $(document).on('click', '.bind_shop', function () {
            //$('#showRefundModal').show();
            $('#showRefundModal').modal('show');
        });


    });
    function uploadFile() {
        var form = document.getElementById('uploadForm');
        var formData = new FormData(form);

        var formData = new FormData($('#uploadForm')[0]);

        $.ajax({
            url: '/fQTrLEivaP.php/user/statistic/import', // 替换为你的PHP脚本路径
            type: 'POST',
            data: formData,
            processData: false,  // 不要处理数据
            contentType: false,  // 不要设置内容类型
            success: function(response) {
                //console.log(response);
                //var res = JSON.parse(response);
                console.log(response);
                if(response.code==1){
                    layer.open({
                        type: 1,
                        area: ['280px', '180px'],
                        content: '<p style="padding: 15px;font-size: 16px;color: #ff0000;">'+response.msg+'</p>',
                        btn: ['确定'], // 弹窗按钮
                        btnAlign:"c",
                        yes: function(index, layero){
                            // 点击确定按钮后的回调函数
                            // index是弹窗的索引，layero是弹窗的DOM对象
                            layer.close(index); // 关闭弹窗
                            window.location='/fQTrLEivaP.php/user/statistic';

                        }
                    });
                } else {
                    layer.open({
                        type: 1,
                        area: ['280px', '180px'],
                        content: '<p style="padding: 15px;font-size: 16px;color: #ff0000;">'+response.msg+'</p>',
                        btn: ['确定'], // 弹窗按钮
                        btnAlign:"c",
                        yes: function(index, layero){
                            // 点击确定按钮后的回调函数
                            // index是弹窗的索引，layero是弹窗的DOM对象
                            layer.close(index); // 关闭弹窗
                        }
                    });
                }
            },
            error: function(xhr, status, error) {
                console.error('Error:', error);
                alert('发生错误，请重试！');
            }
        });


    }
</script>
